package com.game.simplegame.world;

import com.game.simplegame.creature.Creature;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017-04-18.
 */
public class World {

    ArrayList<Creature> creatureArrayList = new ArrayList<Creature>();
    long currentTime = 0;

    public void update(long dtMS){
        long dtSec = dtMS * 24 * 60 / 1000;
        ArrayList<Creature> creatures = new ArrayList<Creature>(creatureArrayList);
        for(int i = 0 ;i < creatures.size();i++){
            creatures.get(i).update(dtSec,this);
        }
        forwardTime(dtSec);
    }

    public void remove(Creature creature){
        if(creatureArrayList.contains(creature)){
            creatureArrayList.remove(creature);
        }
    }

    public void add(Creature creature){
        if(!creatureArrayList.contains(creature)){
            creatureArrayList.add(creature);
        }
    }

    //the world time in second
    public long getTimeInSecond(){
        return currentTime;
    }

    private void forwardTime(long dtSec){
        currentTime += dtSec;
    }

}
